package com.ganwei.plugin;

import cn.hutool.core.collection.CollUtil;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Import;
import org.springframework.stereotype.Component;

import java.util.Map;

/**
 * @BelongsProject: plugin-demo-test
 * @BelongsPackage: com.plugin.demo
 * @Author: Owen
 * @CreateTime: 2022-12-27
 * @Description: 测试类
 * @Version: 1.0
 */
@Import(PluginImportBeanDefinitionRegistrar1.class)
@Component
public class PluginTest implements CommandLineRunner {


    //TODO 不能这样用
//    @PostConstruct
//    public void test() {
//
//        Map<String, DataBaseSPI> beansOfType = SpringUtils.getBeansOfType(DataBaseSPI.class);
//        beansOfType.forEach((key,value) ->{
//            value.getConnection();
//        });
//        System.out.println("222");
//    }

    @Override
    public void run(String... args) throws Exception {
        Map<String, DataBase> beansOfType = SpringUtils.getBeansOfType(DataBase.class);
        if(CollUtil.isNotEmpty(beansOfType)){
            beansOfType.forEach((key,value) ->{
                value.getConnection();
            });
        }

        System.out.println("获取jar包中的类结束");
    }
}
